﻿using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;

namespace Lon.Server
{
    /// <summary>
    /// 权限管理
    /// </summary>
    public class PrivilegeMan
    {
        public static PrivilegeType[] PrivilegeList = new PrivilegeType[] {
                PrivilegeType.EDIT_USER,
                PrivilegeType.EDIT_CONFIG,
                PrivilegeType.VIEW_INFO,
                PrivilegeType.VIEW_ERROR,
                PrivilegeType.VIEW_USER_LOG,
                PrivilegeType.SAVE_IPLIST,
                PrivilegeType.GET_REPORT,
                PrivilegeType.SYS_DIAGNO,
                PrivilegeType.SYS_CLOSE,
            };


        public static bool Test(PrivilegeType target, PrivilegeType standard)
        {
            bool flag = ((target & standard) != 0);
            return flag;
        }

    }

    [Flags]
    public enum PrivilegeType
    {
        NONE = 0,

        [DescriptionAttribute("允许退出程序")]
        SYS_CLOSE = 0x01,

        [DescriptionAttribute("用户账号管理")]
        EDIT_USER = 0x02,

        [DescriptionAttribute("修改配置文件")]
        EDIT_CONFIG = 0x04,

        [DescriptionAttribute("系统日志查看")]
        VIEW_INFO = 0x08,

        [DescriptionAttribute("异常日志查看")]
        VIEW_ERROR = 0x10,

        [DescriptionAttribute("用户操作日志查看")]
        VIEW_USER_LOG = 0x20,

        [DescriptionAttribute("保存IP列表")]
        SAVE_IPLIST = 0x40,

        [DescriptionAttribute("提取日报表")]
        GET_REPORT = 0x80,

        [DescriptionAttribute("系统自检")]
        SYS_DIAGNO = 0x100,

        ALL = SYS_CLOSE | EDIT_USER | EDIT_CONFIG | VIEW_INFO | VIEW_ERROR | VIEW_USER_LOG | SAVE_IPLIST | GET_REPORT | SYS_DIAGNO,
    }
}
